var times = 1;
$(function(){

    $(window).scroll(function(){
        // 当滚动到最底部以上600像素时， 加载新内容
        if ($(document).height() - $(this).scrollTop() - $(this).height()<2000){
            //滚动加载数据
            loadData();
        }
    });

    //window resize
    var currentWidth = 1001;
    $(window).resize(function() {
        var winWidth = $(window).width();
        var conWidth;
        if(winWidth < 660) {
            conWidth = 440;
            col = 2
        } else if(winWidth < 880) {
            conWidth = 660;
            col = 3
        } else if(winWidth < 1001) {
            conWidth = 880;
            col = 4;
        } else {
            conWidth = 1001;
            col = 4;
        }

        if(conWidth != currentWidth) {
            currentWidth = conWidth;
            $('#container').width(conWidth);
            $('#container').BlocksIt({
                numOfCol: col,
                offsetX: 8,
                offsetY: 8
            });
        }
    });

    //初始化数据
    loadData();
});




//Ajax加载数据
function loadData()
{
    $.get('/api.php',{op:"get_picture",catid:cat_id,page:times},function(strhtml){
        $('#container').append(strhtml);
    });

    $('#container').BlocksIt({
        numOfCol:4,
        offsetX: 8,
        offsetY: 8
    });

    $("img.lazy").lazyload({threshold:1000});
    times++;
}